package com.hcinfos.gsoo.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.hcinfos.gsoo.R;

public class TypeGridViewAdapter extends BaseAdapter {
	private LayoutInflater inflater;
	private List<String> items;
	private List<Integer> icons;

	public TypeGridViewAdapter(Context context, List<String> items,
			List<Integer> icons) {
		this.items = items;
		this.icons = icons;
		inflater = LayoutInflater.from(context);

	}

	@Override
	public int getCount() {
		return items.size();
	}

	@Override
	public Object getItem(int position) {
		return items.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = this.inflater.inflate(
					R.layout.adapter_waimai_type_gridview, null);
			holder.iv = (ImageView) convertView
					.findViewById(R.id.itemImageView);
			holder.tv = (TextView) convertView.findViewById(R.id.itemTextView);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		holder.iv.setImageResource(icons.get(position));
		holder.tv.setText(items.get(position));
		return convertView;
	}

	private class ViewHolder {
		ImageView iv;
		TextView tv;
	}

}
